$(function () {
//	var hasP=hasPermission("iqc:user:sqe");
    $("#jqGrid").jqGrid({
        url: '../bill/list',
        datatype: "json",
        colModel: [
			{ label: '送货日期', name: 'invoiceDate', width: 80}, 			
			{ label: '送货单号', name: 'iNVOICENO', width: 80  }, 			
			{ label: '发票编码', name: 'sALESPEOPLEID', width: 80 }, 			
			{ label: '订单编号', name: 'sONO', width: 80  }, 			
			{ label: '订单日期', name: 'soDate', width: 80 }, 			
			{ label: '客户PO', name: 'cUSTREF', width: 80 },
			{ label: '客方货号', name: 'cUSTOMERCODE', width: 80 },
			{ label: '盒式', name: 'cARTONNAME', width: 80 },
			{ label: '纸质', name: 'qUALITY', width: 80 },
			{ label: '规格', name: 'high', width: 80 ,formatter:function(value, options, row){
				if(row.high=='0' || row.high=='0.0'){
					return row.length+'x'+row.width+' '+row.uNITID;
				}else{
					return row.length+'x'+row.width+'x'+row.high+' '+row.uNITID;
				}
				
			}},
			{ label: '数量', name: 'qUANTITY', width: 80 },
			{ label: '订单数量', name: 'sOQUANTITY', width: 80 },
			{ label: '已送数量', name: 'iNVOICEQTY', width: 80 },
			{ label: '未送货数', name: 'noInvoiceQty', width: 80 },
			{ label: '单价', name: 'price', width: 80},
			{ label: '金额', name: 'totalPrice', width: 80},
			{ label: '单重', name: 'weight', width: 80},
			{ label: '重量', name: 'totalWeight', width: 80},
			{ label: '备注', name: 'remark', width: 80}
        ],
		viewrecords: true,
		cellEdit: false,
		cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
		height: 'auto',
        rowNum: 15,
		rowList : [15,30,50,100,200],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		startDate: getFormatDate(new Date(),"startFirst"),
		endDate: getFormatDate(new Date(),""),
		cUSTOMERID: '',
		customerList:[]
	},
	created: function() {
		//获取aql信息
		this.getCustomerList();
    },
	methods: {
		query: function () {
			this.editFlag=0;
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData:{
                	'cUSTOMERID': vm.cUSTOMERID,
                	'startDate': vm.startDate,
                	'endDate': vm.endDate
                	},
                page:1 
            }).trigger("reloadGrid");
		},
		reset: function () {
			vm.startDate=getFormatDate(new Date(),"startFirst");
			vm.endDate=getFormatDate(new Date(),"");
			vm.cUSTOMERID='';
			vm.query();
		},
		getCustomerList: function(){
			
			$.get("../bill/queryCustomerlist", function(r){
				vm.customerList=r.list;
            });
			
		},
		exportMoonBillExcel: function(){
			if(""==vm.cUSTOMERID || null==vm.cUSTOMERID || undefined==vm.cUSTOMERID){
				confirm('未选择客户，确定导出全部？', function(index){
					vm.doExport();
				});
			}else{
				vm.doExport();
			}
		},
		doExport: function(){
			var url="../bill/exportMoonBillExcel?cUSTOMERID="+vm.cUSTOMERID+"&startDate="+vm.startDate+"&endDate="+vm.endDate;
            var elemIF = document.createElement("iframe");   
            elemIF.src = url;   
            elemIF.style.display = "none";   
            document.body.appendChild(elemIF); 
		},
		getRealValue: function(pValue) {
            if (/msie/.test(navigator.userAgent.toLowerCase())) {
                var oReg2 = /(\s+\w+=)('|")?(.*?)('|")?(?=\s+\w+=|\s*>|\s*\/>)/gi;
                pValue = pValue.replace(oReg2, "$1\"$3\"");
                var oReg = /^<(input|INPUT).*id=\"(.*?)\"/m;
                var val = pValue.match(oReg);
                return !val ? pValue : $("#" + val[2]).val();
            }
            else {
                var regExp = /^<.*? id=['"](.*?)['"].*?>$/;
                var val = pValue.match(regExp);
                return !val ? pValue : $("#" + val[1]).val();
            }
        }
	}
});

/**************************************时间格式化处理************************************/
function getFormatDate(date,type) {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    if(type=='startFirst'){
      currentdate = year + seperator1 + month + seperator1 + "01";
    }else{
      currentdate = year + seperator1 + month + seperator1 + strDate;
    }
    return currentdate;
}